package org.dromara.neutrinoproxy.client.event;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class EventContainer {


    private Set<IEventCallback> callbacks = new HashSet<>();

    /**
     * 发布事件
     * @param event
     */
    public void post(BaseEvent event){
        for(IEventCallback callback :callbacks){
            callback.onReceive(event);
        }
    }

    public void subscribe(IEventCallback callback){
        callbacks.add(callback);
    }

    public void unsubscribe(IEventCallback callback){
        callbacks.remove(callback);
    }


    private static EventContainer instance;

    /**
     * 获取单例
     */
    public static EventContainer getInstance(){
        if(instance == null){
            instance = new EventContainer();
        }
        return instance;
    }

}
